package com.ijiuchuang.jc_localization.network;

import com.ijiuchuang.jc_localization.app.Config;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by Veev on 2016/6/7
 *
 * @link 384506557@qq.com
 */
public class Client {

    public static OkHttpClient defaultHttpClient = new OkHttpClient();

    public static OkHttpClient bmobPostClient() {
        OkHttpClient httpClient = new OkHttpClient.Builder()
                .addInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Chain chain) throws IOException {
                        Request request = chain.request()
                        .newBuilder()
                        .addHeader("X-Bmob-Application-Id", Config.BOMB_APP_ID)
                        .addHeader("X-Bmob-REST-API-Key", Config.BMOB_REST_API)
                        .addHeader("Content-Type", "application/json")
                        .build();
                        return chain.proceed(request);
                    }
                })
                .build();
        return httpClient;
    }

    public static OkHttpClient bmobGetClient() {
        OkHttpClient httpClient = new OkHttpClient.Builder()
                .addInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Chain chain) throws IOException {
                        Request request = chain.request()
                                .newBuilder()
                                .addHeader("X-Bmob-Application-Id", Config.BOMB_APP_ID)
                                .addHeader("X-Bmob-REST-API-Key", Config.BMOB_REST_API)
                                .build();
                        return chain.proceed(request);
                    }
                })
                .build();
        return httpClient;
    }

    public static OkHttpClient apiStoreClient() {
        OkHttpClient httpClient = new OkHttpClient.Builder()
                .addInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Chain chain) throws IOException {
                        Request request = chain.request()
                                .newBuilder()
                                .addHeader("apikey", Config.BAIDU_apiKey)
                                .build();
                        return chain.proceed(request);
                    }
                })
                .build();
        return httpClient;
    }
}
